package com.module.app.emoji.model

import com.module.app.base.BaseViewModel
import com.module.app.bean.ListViewBean
import com.module.app.ext.emojiDelBtnFlow
import com.module.app.network.MyBaseResponse
import com.module.base.ext.request
import com.module.frame.ext.postEvent
import com.module.third.learcloud.SUCCESS_CODE
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

class TTEmojiViewModel : BaseViewModel() {

    fun getData() {
        request({
            withContext(Dispatchers.IO) {
                var map: Map<String, com.module.app.emoji.bean.Emoji> = com.module.app.emoji.EmojiUtils.EMOJI_MAP_TT
                val list: MutableList<com.module.app.emoji.bean.Emoji> = ArrayList()
                val it = map.entries.iterator()
                while (it.hasNext()) {
                    val (_, value) = it.next()
                    list.add(value)
                }
                return@withContext MyBaseResponse(
                    SUCCESS_CODE,
                    "",
                    list
                )
            }
        }, {
            postEvent(listFlow, ListViewBean(true, it, true))
        }, {
            postEvent(errorFlow, it)
        }, false)
    }

    fun onClickGoBack() {
        postEvent(emojiDelBtnFlow, true)
    }
}